package asteroids.model.programs;

import be.kuleuven.cs.som.annotate.*;

public abstract class  ComposedExpression<T> extends Expression<T> {




	@Basic @Raw
	public abstract int getNbOperands();


	@Basic @Raw
	public abstract Expression<T> getOperandAt(int index)
			throws IndexOutOfBoundsException;


	public boolean canHaveAsOperandAt(Expression<T> expression, int index) {
		return (expression != null) && (!expression.hasAsSubExpression(this)) && (index > 0);
	}


	protected abstract void setOperandAt(int index, Expression<T> operand);


	@Override
	public boolean hasAsSubExpression(Expression<? extends T> expression) {
		if (expression == this)
			return true;
		for (int pos = 1; pos <= getNbOperands(); pos++)
			if (getOperandAt(pos).hasAsSubExpression(expression))
				return true;
		return false;
	}






}
